﻿<?php
	include_once './inc/isLogin.php';
?>
<script src="../includes/common.js" type="text/javascript"></script>
<script src="../includes/jquery-1.7.min.js" type="text/javascript"></script>
<script src="../mfu/jquery.MultiFile.js" type="text/javascript"></script>
<style>
div{
	vertical-align: middle;
}
.show_post {
	padding:30px;padding-top:0;
}
.show_post p {
	border-bottom: 1px dashed #EB6100;
    padding: 10px;
}
.show_post p select {
	border-color: #7F9DB9;
	border-style: solid;
	border-width: 1px;
	padding: 2px;
}
.left_post {
	width:128px;
	display:block;
	float:left;
	text-align:right;
	padding-right:20px;
}
.required {
	color: #FF0000;
	display: inline-block;
	font-size: 17px;
	padding-right:5px;
	vertical-align: middle;
}
.text1 {
	border: 1px solid #7F9DB9;
	height: 30px;
	margin-right: 4px;
	padding: 3px 2px 0;
	vertical-align: middle;
	width: 330px;
}
.text2{
	width: 170px !important;
}

.fabu1 {
    background: url("../images/psearch.gif") no-repeat scroll 0 -100px transparent;
    border: medium none;
    color: #FFFFFF;
    cursor: pointer;
    font: 700 14px/34px "宋体",sans-serif;
    height: 34px;
    margin-right: 3px;
    overflow: hidden;
    text-align: center;
    width: 107px;
	margin-left:120px;
}
.fabu1:hover{
	padding-left:5px;
}
.list_r{

	float:right;
}
.list_l_one{
	margin-right:15px;
}
.list_r_one{
	margin-right:15px;
}
#MyAnjuke .tab {
    background: none repeat scroll 0 0 #F4F8FA;
    clear: both;
    height: 25px;
    padding-left: 9px;
}
#MyAnjuke .tab h1 dl {
    height: 25px;
}
#MyAnjuke .tab h1 dl dt {
    background: url("http://pages.anjukestatic.com/img/myanjuke/cs10/myanjukeicons.png") no-repeat scroll 0 0 transparent;
    float: left;
    height: 25px;
}
#MyAnjuke .tab h1 dl dt.tL {
    background-color: white;
    background-position: 0 -479px;
    width: 8px;
}
#MyAnjuke .tab h1 dl dt.t0 {
    background-color: white;
    background-image: none;
    border-top: 1px solid #D8EFF7;
    color: #333333;
    font: bold 14px/28px '宋体';
    height: 24px;
    padding: 0 7px;
}
#MyAnjuke .tab h1 dl dt.tR {
    background-color: white;
    background-position: -92px -479px;
    width: 12px;
}
#MyAnjuke .tab h1 dl dt.refresh {
    background-color: white;
    background-position: 0 -598px;
    border-top: 1px solid #D8EFF7;
    line-height: 26px;
    padding-right: 3px;
    text-indent: 22px;
}
#MyAnjuke .show {
    margin: 15px 15px 0;
    padding-bottom: 35px;
    width: 705px;
}
#MyAnjuke .tab ul li {
    float: left;
    height: 25px;
    line-height: 25px;
    margin-right: 9px;
    text-align: center;
    width: 100px;
}
#MyAnjuke .tab ul li a {
    background: url("http://pages.anjukestatic.com/img/myanjuke/cs10/myanjukeicons.png") no-repeat scroll left -562px transparent;
    color: #333333;
    display: block;
    font-family: SimSun;
    font-size: 14px;
    height: 25px;
    line-height: 25px;
    width: 100px;
}
#MyAnjuke .tab ul li a:hover {
    background: url("http://pages.anjukestatic.com/img/myanjuke/cs10/myanjukeicons.png") no-repeat scroll left -526px #FFFFFF;
    text-decoration: none;
}
#MyAnjuke .tab ul li a.on {
    background: url("http://pages.anjukestatic.com/img/myanjuke/cs10/myanjukeicons.png") no-repeat scroll left -478px #FFFFFF;
    font-weight: bold;
}
.multipage{
	text-align:center;
	padding-bottom:5px;
}
</style>
<?php
	require_once("../includes/configure.php");
	require_once("../includes/database.php");
	require_once("../includes/func.php");
	$db = Database::Connect();

	//添加,或者更新
	if($_POST['submit']){
		 //
		if(true){
			//循环上传
			$debug_echo = false;
			$upload_result = '';
			$insert_db_str = '';
			$file_input_name = 'upload_files';//表单的文件input name
			for($upload_index=0;$upload_index<count($_FILES[$file_input_name][name]);$upload_index++){
				$target = "../upload/xiaoqu/";
				//文件存放位置，用这种分文件加的方式，类似二分法原理，当文件比较多的时候，可以加快一点速度
				$img_file_floder = $target.date('Ymd');
				if(!file_exists($img_file_floder))
				{
				   //检查是否有该文件夹，如果没有就创建，并给予最高权限
				   mkdir("$img_file_floder", 0755);
				}
				//中文也没有问题,但是不建议用,特别是在linux这种环境,自己根据自己需要做调整吧
				$target = $img_file_floder .'/'. time().'_'.rand(1,250).substr(basename($_FILES[$file_input_name]['name'][$upload_index]),strlen(basename($_FILES[$file_input_name]['name'][$upload_index]))-4);
				$this_file_name = basename($_FILES[$file_input_name]['name'][$upload_index]) ;
				$ok=1;

				$uploaded_size = $_FILES["upload_files"]["size"][$upload_index];
				$uploaded_type = $_FILES["upload_files"]["type"][$upload_index];
				//This is our size condition
				if ($uploaded_size > 2000*1024) {
					if($debug_echo)echo "你上传的文件' $this_file_name '太大了.<br/>";
					$upload_resul.="你上传的文件' $this_file_name '太大了.<br/>";
					$ok=0;
				}

				//This is our limit file type condition
				if (!($uploaded_type =="image/jpeg" || $uploaded_type =="image/pjpeg" ||$uploaded_type =="image/gif"||$uploaded_type =="image/png")) {
					if($debug_echo && $this_file_name!="")echo "上传文件' $this_file_name '类型出错<br/>";
					$upload_resul.="上传文件' $this_file_name '类型出错<br/>";
					$ok=0;
				}


				if ($ok==0) { //Here we check that $ok was not set to 0 by an error
					if($debug_echo)echo "' $this_file_name '文件没有上传成功.<br/>";
				} else 	{ //If everything is ok we try to upload it
					if(move_uploaded_file($_FILES[$file_input_name]['tmp_name'][$upload_index], $target)) {
						$insert_db_str .=$target.';';
						if($debug_echo)echo "文件 ' $this_file_name ' 上传成功 <br/>";
						$upload_resul.="文件 ' $this_file_name ' 上传成功 <br/>";
					} else 	{
						if($debug_echo)echo "对不起,上传文件' $this_file_name ' 的时候发生了错误.";
						$upload_resul.="对不起,上传文件' $this_file_name ' 的时候发生了错误.";
					}
				}
			}
		}
		 //


		$xiaoquming = $db->Encode($_POST['xiaoquming']);
		$quyu = $db->Encode($_POST['quyu']);
		$quyu2 = $db->Encode($_POST['quyu2']);
		$dizhi = $db->Encode($_POST['dizhi']);
		$gaikuang = $db->Encode($_POST['gaikuang']);
		
		$wuyeleixing = $db->Encode($_POST['wuyeleixing']);
		$jungongshijian = $db->Encode($_POST['jungongshijian']);
		$kaifashang = $db->Encode($_POST['kaifashang']);
		$wuyegongsi = $db->Encode($_POST['wuyegongsi']);
		$wuyefei = $db->Encode($_POST['wuyefei']);
		$isSystem = $db->Encode($_POST['isSystem']);
		if(!$isSystem){
			$isSystem = 0;
		}else{
			$isSystem = 1;
		}
		$is_hot = $db->Encode($_POST['is_hot']);
		if(!$is_hot){
			$is_hot = 0;
		}else{
			$is_hot = 1;
		}
		
		
		if($_POST['action_submit']=='action_submit'){
			$is_add = 1;
			$sql = "insert into xiaoqu" .
				"(xiaoquming,quyu,quyu2,dizhi,gaikuang,wuyeleixing,jungongshijian,kaifashang,wuyegongsi,
				wuyefei,tupian,isSystem,is_hot)" .
				" values('$xiaoquming','$quyu','$quyu2','$dizhi','$gaikuang','$wuyeleixing','$jungongshijian','$kaifashang','$wuyegongsi','$wuyefei','$insert_db_str',$isSystem,$is_hot)";
			$db->Execute($sql);
			$result_info = '发布成功咯！';
		}else{
			$this_id = $db->Encode($_POST['this_id']);
			$sql = "update xiaoqu set xiaoquming='$xiaoquming',quyu='$quyu',quyu2='$quyu2',
					dizhi='$dizhi',gaikuang='$gaikuang',wuyeleixing='$wuyeleixing',
					jungongshijian='$jungongshijian',kaifashang='$kaifashang',wuyegongsi='$wuyegongsi',
					wuyefei='$wuyefei',tupian=CONCAT(tupian,'$insert_db_str'),isSystem=$isSystem,is_hot=$is_hot where this_id = $this_id";
			$db->Execute($sql);
			$result_info = '更新成功！';
		}

		echo "<script>alert('$result_info');location='./xiaoqu.php';</script>";	

	}
	//添加,或者更新
	
	if((!is_numeric($_GET['id']))&&$_GET['action']=='add'){
		//添加
		$is_add = 1;
	}else{
		$sql = "select * from xiaoqu
				where this_id=".$_GET['id'];
		$xiaoqu_detail = $db->GetSingleRow($sql);
	}
	
	$zufang_quyu_array = $db->getConfigurationArray('zufang_quyu');
	
?>
<div class="right_container">
  <div id="MyAnjuke">
    <div class="tab">
      <h1 style="padding:0;margin:0;">
        <dl style="padding:0;margin:0;">
          <dt class="tL"></dt>
          <dt class="t0"><?if($is_add){echo "添加小区信息";}else{?>编辑小区信息 - <?php echo $xiaoqu_detail->xiaoquming;}?></dt>
          <dt class="tR"></dt>
        </dl>
      </h1>
    </div>
    <div class="" style="padding-bottom:100px;">
		<form id="qiugou_post" method="post" name="qiuzu_post" style="vertical-align: middle;" action="" enctype="multipart/form-data">
			<?
				if($is_add){
			?>
				<input type="hidden" value="action_submit" id="action_submit" name="action_submit">
			<?php
				}else{
			?>
				<input type="hidden" value="<?php echo $xiaoqu_detail->this_id;?>" id="this_id" name="this_id">
			<?php
				}
			?>
        <p style="color:green;padding:5px;font-size:17px;padding-left:122px;">
			<strong><?php echo $result_info;?></strong>
		</p>
		<p> <span class="left_post"><span class="required"></span>标题:</span>
          <input type="text" class="text1" value="<?php echo $xiaoqu_detail->xiaoquming;?>" id="xiaoquming" name="xiaoquming">
        </p>
        <p> <span class="left_post">区域:</span>
          <select name="quyu" id="quyu" onchange="getShangQuan2()">
            <option value="">--区域--</option>
            <?
				for($ii=0;$ii<count($zufang_quyu_array);$ii++){
					echo "<option ";
					if($xiaoqu_detail->quyu==$zufang_quyu_array[$ii]['this_id']){
						echo " selected ";
					}
					echo " value='".$zufang_quyu_array[$ii]['this_id']."'> ".$zufang_quyu_array[$ii]['value']."</option>";
				}
			?>
          </select>
          <span id="quyu2_div">
			  <select name="quyu2" id="quyu2">
				<option value="">--商圈--</option>
			  </select>
		  </span>
        </p>
		<p> <span class="left_post"><span class="required"></span>详细地址:</span>
          <input type="text" class="text1" value="<?php echo $xiaoqu_detail->dizhi;?>" id="dizhi" name="dizhi">
        </p>
        <p>
			<span class="left_post"><span class="required"></span>概况:</span>
		  <textarea name="gaikuang" id="gaikuang" style=" height: 130px;width: 330px;"><?php echo $xiaoqu_detail->gaikuang;?></textarea>
        </p>
		<p>
			<span class="left_post"><span class="required"></span>实景图:</span>
			<div id="custom-demo" class="demo">
		  <script type="text/javascript">
				$(function() {
				$('#custom_file_upload').uploadify({
					'uploader' : '../uploadify/uploadify.php',
					'swf' : '../uploadify/uploadify.swf',
					'cancelImage' : '../uploadify/uploadify-cancel.png',
					  'folder'         : '../upload/xiaoqu',
					  'multi'          : true,
					  'auto'           : true,
					   'removeCompleted': false,
					  'fileExt'        : '*.jpg;*.gif;*.png',
					  'fileDesc'       : 'Image Files (.JPG, .GIF, .PNG)',
					  'queueID'        : 'custom-queue',
					  'queueSizeLimit' : 5,
					  　buttonText :"上传图片",
					  'simUploadLimit' : 3,
					  'sizeLimit'   : 102400,
					  'onSelectOnce'   : function(event,data) {
						  $('#status-message').text(data.filesSelected + ' 文件已经添加到上传队列.');
						},
					  'onAllComplete'  : function(event,data) {
						  $('#status-message').text(data.filesUploaded + ' 文件已上传, ' + data.errors + ' 错误.');
						}
					});
				});
				</script>
        <style type="text/css">
			#custom-demo .uploadifyQueueItem {
			  background-color: #FFFFFF;
			  border: none;
			  border-bottom: 1px solid #E5E5E5;
			  font: 11px Verdana, Geneva, sans-serif;
			  height: 50px;
			  margin-top: 0;
			  padding: 10px;
			  width: 350px;
			}
			#custom-demo .uploadifyError {
			  background-color: #FDE5DD !important;
			  border: none !important;
			  border-bottom: 1px solid #FBCBBC !important;
			}
			#custom-demo .uploadifyQueueItem .cancel {
			  float: right;
			}
			#custom-demo .uploadifyQueue .completed {
			  color: #C5C5C5;
			}
			#custom-demo .uploadifyProgress {
			  background-color: #E5E5E5;
			  margin-top: 10px;
			  width: 100%;
			}
			#custom-demo .uploadifyProgressBar {
			  background-color: #0099FF;
			  height: 3px;
			  width: 1px;
			}
			#custom-demo #custom-queue {
			  border: 1px solid #E5E5E5;
			  height: 213px;
			margin-bottom: 10px;
			  width: 370px;
			}
			.MultiFile-list{
				padding-left:135px;
			}
			.MultiFile-label{
				float:left; padding:5px;border: 1px solid;margin:5px;
			}
		</style>
        <div class="floatL" style="padding-left:14px;">
		<input type="file" class="multi" maxlength="100" accept="jpg|png|gif" name="upload_files[]"/>
		</div>
        </p>
		<p style="clear:both;">
			<span class="left_post"><span class="required"></span>物业类型:</span>
          <input type="text" class="text1" value="<?php echo $xiaoqu_detail->wuyeleixing;?>" id="wuyeleixing" name="wuyeleixing">
        </p>
		<p style="clear:both;">
			<span class="left_post"><span class="required"></span>竣工时间:</span>
          <input type="text" class="text1" value="<?php echo $xiaoqu_detail->jungongshijian;?>" id="jungongshijian" name="jungongshijian">
        </p>
		<p style="clear:both;">
			<span class="left_post"><span class="required"></span>开发商:</span>
          <input type="text" class="text1" value="<?php echo $xiaoqu_detail->kaifashang;?>" id="kaifashang" name="kaifashang">
        </p>
		<p style="clear:both;">
			<span class="left_post"><span class="required"></span>物业公司:</span>
          <input type="text" class="text1" value="<?php echo $xiaoqu_detail->wuyegongsi;?>" id="wuyegongsi" name="wuyegongsi">
        </p>
		<p style="clear:both;">
			<span class="left_post"><span class="required"></span>物业费:</span>
          <input type="text" class="text1" value="<?php echo $xiaoqu_detail->wuyefei;?>" id="wuyefei" name="wuyefei">
        </p>
		<p style="clear:both;">
			<span class="left_post"><span class="required"></span>&nbsp;</span>
			<input type="checkbox" <?php if($xiaoqu_detail->isSystem)echo ' checked="checked"';?> name="isSystem" id="isSystem" />设置为系统小区
			<input type="checkbox" <?php if($xiaoqu_detail->isSystem)echo ' checked="checked"';?> name="is_hot" id="is_hot" />Hot(系统排序用)
        </p>
		<p>
			<input type="submit" value="提交" class="fabu1" id="submit" name="submit">
		</p>
      </form>
    </div>
  </div>
</div>
</div>
<script>
	getShangQuan3('<?php echo $xiaoqu_detail->quyu2;?>');
</script>
<?php
	$db->Close();
?>